/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __M2_MESH_LOAD_IMPL_H__
#define __M2_MESH_LOAD_IMPL_H__

#include "OgreVertexBoneAssignment.h"
#include "OgreResource.h"

#include "M2.h"
#include "M2Model.h"

#include "GPrerequisites.h"

namespace GNgine
{
	class M2File;
	class M2SkinFile;
	/** Internal class that used to load m2 mesh data into Ogre mesh.
        @remarks
			This class shouldn't used by user,just an implementation of m2 mesh loader.
    */
	class M2MeshLoadImpl
	{
	public:
		~M2MeshLoadImpl();
		M2MeshLoadImpl(Ogre::Mesh *mesh);

		void load(std::string path);//load mesh data into ogre
	private:
		Ogre::SubMesh* createOgreSubMesh(M2SubMesh m2SubMesh);
		void initM2Skeleton();
		void initM2SubMeshes();
		void initVertexBoneAssignment(Ogre::SubMesh* submesh,int vertexIndex);
	private:
		M2Model* _m2Model;
		M2File* _m2File;
		M2SkinFile* _skinFile;
		M2TexUnit* _m2TexUnits;
		M2SubMesh* _m2SubMeshes;
		M2Vertex* _m2Vertices;
		unsigned short *_m2Indices;
		int _m2SubMeshCount;
		
		Ogre::Mesh *_mesh;
		Ogre::Vector3 _minAABB;//Mesh AABB
		Ogre::Vector3 _maxAABB;
		Ogre::Real _radiusAABB;
		Ogre::String _materialName;

		int _vertexSize;//ogre vertex decl vertex size
	};
}

#endif
